disp('%%%%In this file we have a series of measures to systematically produce alternate start points via')
disp('%%%%various methods, in an effort to discover a superior solution.  If no improvements on the')
disp('%%%%objective function can be found from any of the below alternate start points, that suggests we')
disp('%%%%have converged to a global optimum.')



if Model==1
    %%%%This is the basic version of the regression model: 
    %%%%Variables: 1 NBHD-Inc, 2 NBHD UninsMinors, 3 fem, 4 Black, 5 Hispanic, 6 Grade-5, 7 CONST

    %%%%VARIABLE GROUP 1: 1 NBHD-Inc, 2 NBHD UninsMinors
    grp1E  = [1; 1; zeros(5,1); zeros(7,1)] ; 
    grp1L  = [zeros(7,1); 1; 1; zeros(5,1)] ; 
    grp1EL = [1; 1; zeros(5,1); 1; 1; zeros(5,1)] ; 
    %%%%VARIABLE GROUP 2: 3 fem, 4 Black, 5 Hispanic, 6 Grade-5
    grp2E  = [zeros(2,1); 1; 1; 1; 1; 0; zeros(7,1)] ; 
    grp2L  = [zeros(7,1); zeros(2,1); 1; 1; 1; 1; 0] ; 
    grp2EL = [zeros(2,1); 1; 1; 1; 1; 0; zeros(2,1); 1; 1; 1; 1; 0] ; 

    VarGroups = [grp1E grp1L grp1EL grp2E grp2L grp2EL] ;
elseif Model==2
    %%%%This is the basic version of the regression model: 
    %%%%Variables: 1 NBHD-Inc, 2 NBHD UninsMinors, 3 fem, 4 Black, 5 Hispanic, 6 Dist2, 7 Dist3, 8 Grade-5, 9 CONST

    %%%%VARIABLE GROUP 1: 1 NBHD-Inc, 2 NBHD UninsMinors
    grp1E  = [1; 1; zeros(7,1); zeros(9,1)] ; 
    grp1L  = [zeros(9,1); 1; 1; zeros(7,1)] ; 
    grp1EL = [1; 1; zeros(7,1); 1; 1; zeros(7,1)] ; 
    %%%%VARIABLE GROUP 2: 3 fem, 4 Black, 5 Hispanic, 8 Grade-5
    grp2E  = [zeros(2,1); 1; 1; 1; zeros(2,1); 1; 0; zeros(9,1)] ; 
    grp2L  = [zeros(9,1); zeros(2,1); 1; 1; 1; zeros(2,1); 1; 0] ; 
    grp2EL = [zeros(2,1); 1; 1; 1; zeros(2,1); 1; 0; zeros(2,1); 1; 1; 1; zeros(2,1); 1; 0] ; 
    %%%%VARIABLE GROUP 3: 6 Dist2, 7 Dist3
    grp3E  = [zeros(5,1); 1; 1; zeros(2,1); zeros(9,1)] ; 
    grp3L  = [zeros(9,1); zeros(5,1); 1; 1; zeros(2,1)] ; 
    grp3EL = [zeros(5,1); 1; 1; zeros(2,1); zeros(5,1); 1; 1; zeros(2,1)] ; 

    VarGroups = [grp1E grp1L grp1EL grp2E grp2L grp2EL grp3E grp3L grp3EL] ;
elseif Model==3
    %%%%This is the basic version of the regression model: 
    %%%%theta_E Variables: 1 NBHD-Inc, 2 NBHD UninsMinors, 3 HELPER_ADULT, 4 HELPER_PEER, 
    %%%%                   5 fem, 6 Black, 7 Hispanic, 8 Dist2, 9 Dist3, 10 Grade-5, 11 CONST
    %%%%------------------------------------------------------------------------------------------------------
    %%%%theta_L Variables:  1 NBHD-Inc, 2 NBHD UninsMinors, 3 HELPER_ADULT, 4 HELPER_PEER, 
    %%%%                    5 MathFav, 6 MathLeast, 7 EXTRINSIC, 8 INTRINSIC, 9 fem, 
    %%%%                    10 Black, 11 Hispanic, 12 Dist2, 13 Dist3, 14 Grade-5, 15 CONST

    %%%%VARIABLE GROUP 1: 1 NBHD-Inc, 2 NBHD UninsMinors
    grp1E  = [1; 1; zeros(9,1); zeros(15,1)] ;
    grp1L  = [zeros(11,1); 1; 1; zeros(13,1)] ;
    grp1EL = [1; 1; zeros(9,1); 1; 1; zeros(13,1)] ;
    %%%%VARIABLE GROUP 2: 3 HELPER_ADULT, 4 HELPER_PEER 
    grp2E  = [zeros(2,1); 1; 1; zeros(7,1); zeros(15,1)] ;
    grp2L  = [zeros(11,1); zeros(2,1); 1; 1; zeros(11,1)] ;
    grp2EL = [zeros(2,1); 1; 1; zeros(7,1); zeros(2,1); 1; 1; zeros(11,1)] ;
    %%%%VARIABLE GROUP 3E: 5 fem, 6 Black, 7 Hispanic, 10 Grade-5
    grp3E  = [zeros(4,1); 1; 1; 1; zeros(2,1); 1; 0; zeros(15,1)] ;
    %%%%VARIABLE GROUP 3L: 9 fem, 10 Black, 11 Hispanic, 14 Grade-5
    grp3L  = [zeros(11,1); zeros(8,1); 1; 1; 1; zeros(2,1); 1; 0] ;
    %%%%VARIABLE GROUP 3EL:
    grp3EL = [zeros(4,1); 1; 1; 1; zeros(2,1); 1; 0; zeros(8,1); 1; 1; 1; zeros(2,1); 1; 0] ;
    %%%%VARIABLE GROUP 4E: 8 Dist2, 9 Dist3
    grp4E  = [zeros(7,1); 1; 1; zeros(2,1); zeros(15,1)] ;
    %%%%VARIABLE GROUP 4L: 12 Dist2, 13 Dist3
    grp4L  = [zeros(11,1); zeros(11,1); 1; 1; zeros(2,1)] ;
    %%%%VARIABLE GROUP 4EL: 
    grp4EL = [zeros(7,1); 1; 1; zeros(2,1); zeros(11,1); 1; 1; zeros(2,1)] ;

    VarGroups = [grp1E grp1L grp1EL grp2E grp2L grp2EL grp3E grp3L grp3EL grp4E grp4L grp4EL] ;
elseif Model==4.05
    %%%%This is the basic version of the regression model:
    %%%%theta_E Variables:  1 NBHD-Inc, 2 NBHD UninsMinors, 3 HELPER_ADULT, 4 HELPER_PEER,
    %%%%                    5 fem, 6 Black, 7 Hispanic, 8 Dist2, 9 Dist3, 10 Grade-5,
    %%%%                    11 CONST, 12 NO_INTERNET, 13 MOBILEFRAC, 14 TABLETFRAC
    %%%%--------------------------------------------------------------------------------------------------
    %%%%theta_L Variables:  1 NBHD-Inc, 2 NBHD UninsMinors, 3 #GamingSys, 4 GamingWkDay,
    %%%%                    5 WkDayNet, 6 HELPER_ADULT, 7 HELPER_PEER, 8 MathFav,
    %%%%                    9 MathLeast, 10 FracSocialSuperv, 11 Sports, 12 music,
    %%%%                    13 OtherActiv, 14 EXTRINSIC, 15 INTRINSIC, 16 fem,
    %%%%                    17 Black, 18 Hispanic, 19 Dist2, 20 Dist3, 21 Grade-5, 22 CONST
    %%%%                    23 TimeStudy, 24 TimeScreen, 25 NO_INTERNET, 26 MOBILEFRAC, 27 TABLETFRAC,

    %%%%VARIABLE GROUP 1: 1 NBHD-Inc, 2 NBHD UninsMinors
    grp1E  = [1; 1; zeros(12,1); zeros(27,1)] ;
    grp1L  = [zeros(14,1); 1; 1; zeros(25,1)] ;
    grp1EL = [1; 1; zeros(12,1); 1; 1; zeros(25,1)] ;
    %%%%VARIABLE GROUP 2E: 3 HELPER_ADULT, 4 HELPER_PEER 
    grp2E  = [zeros(2,1); 1; 1; zeros(10,1); zeros(27,1)] ;
    %%%%VARIABLE GROUP 2L: 6 HELPER_ADULT, 7 HELPER_PEER, 8 MathFav, 9 MathLeast, 14 EXTRINSIC, 15 INTRINSIC
    grp2L  = [zeros(14,1); zeros(5,1); 1; 1; 1; 1; zeros(4,1); 1; 1; zeros(12,1)] ; 
    %%%%VARIABLE GROUP 2EL: 
    grp2EL = [zeros(2,1); 1; 1; zeros(10,1); zeros(5,1); 1; 1; 1; 1; zeros(4,1); 1; 1; zeros(12,1)] ;
    %%%%VARIABLE GROUP 3E: 5 fem, 6 Black, 7 Hispanic, 10 Grade-5
    grp3E  = [zeros(4,1); 1; 1; 1; zeros(2,1); 1; zeros(4,1); zeros(27,1)] ;
    %%%%VARIABLE GROUP 3L: 16 fem, 17 Black, 18 Hispanic, 21 Grade-5
    grp3L  = [zeros(14,1); zeros(15,1); 1; 1; 1; zeros(2,1); 1; zeros(6,1)] ;
    %%%%VARIABLE GROUP 3EL:
    grp3EL = [zeros(4,1); 1; 1; 1; zeros(2,1); 1; zeros(4,1); zeros(15,1); 1; 1; 1; zeros(2,1); 1; zeros(6,1)] ;
    %%%%VARIABLE GROUP 4E: 8 Dist2, 9 Dist3
    grp4E  = [zeros(7,1); 1; 1; zeros(5,1); zeros(27,1)] ;
    %%%%VARIABLE GROUP 4L: 19 Dist2, 20 Dist3
    grp4L  = [zeros(14,1); zeros(18,1); 1; 1; zeros(7,1)] ;
    %%%%VARIABLE GROUP 4EL: 
    grp4EL = [zeros(7,1); 1; 1; zeros(5,1); zeros(18,1); 1; 1; zeros(7,1)] ;
    %%%%VARIABLE GROUP 5L: 3 #GamingSys, 4 GamingWkDay, 5 WkDayNet, 10 FracSocialSuperv, 11 Sports, 12 music, 13 OtherActiv
    grp5L  = [zeros(14,1); zeros(2,1); 1; 1; 1; zeros(4,1); 1; 1; 1; 1; zeros(14,1)] ;
    %%%%VARIABLE GROUP 6E: 12 NO_INTERNET, 13 MOBILEFRAC, 14 TABLETFRAC 
    grp6E  = [zeros(11,1); 1; 1; 1; zeros(27,1)] ;
    %%%%VARIABLE GROUP 6L: 23 TimeStudy, 24 TimeScreen, 25 NO_INTERNET, 26 MOBILEFRAC, 27 TABLETFRAC
    grp6L  = [zeros(14,1); zeros(22,1); 1; 1; 1; 1; 1] ;
    %%%%VARIABLE GROUP 6EL:  
    grp6EL = [zeros(11,1); 1; 1; 1; zeros(22,1); 1; 1; 1; 1; 1] ;

    VarGroups = [grp1E grp1L grp1EL grp2E grp2L grp2EL grp3E grp3L grp3EL grp4E grp4L grp4EL grp5L grp6E grp6L grp6EL] ;

    VarGroups = [grp1E grp1L grp1EL grp2E grp2L grp2EL grp3E grp3L grp3EL grp4E grp4L grp4EL] ;

elseif Model==4.085
    %%%%%SPECIFICATION 6 IN TABLES 2 AND 3
    %%%%theta_E Variables:  1 NBHD-Inc, 2 NBHD UninsMinors, 3 HELPER_ADULT, 4 HELPER_PEER,
    %%%%                    5 fem, 6 Black, 7 Hispanic, 8 Dist2, 9 Dist3, 10 Grade-5,
    %%%%                    11 CONST, 12 NO_INTERNET, 13 MOBILEFRAC, 14 TABLETFRAC
    %%%%                    15 InvolvedParent, 16 BigFam, 17 middlechild, 18 youngestchild
    %%%%------------------------------------------------------------------------------------------------------
    %%%%theta_L Variables:  1 NBHD-Inc, 2 NBHD UninsMinors, 3 #GamingSys, 4 GamingWkDay,
    %%%%                    5 WkDayNet, 6 HELPER_ADULT, 7 HELPER_PEER, 8 MathFav,
    %%%%                    9 MathLeast, 10 FracSocialSuperv, 11 Sports, 12 music,
    %%%%                    13 OtherActiv, 14 EXTRINSIC, 15 INTRINSIC, 16 fem,
    %%%%                    17 Black, 18 Hispanic, 19 Dist2, 20 Dist3, 21 Grade-5, 22 CONST
    %%%%                    23 TimeStudy, 24 TimeScreen, 25 NO_INTERNET, 26 MOBILEFRAC, 27 TABLETFRAC,
    %%%%                    28 InvolvedParent, 29 BigFam, 30 middlechild, 31 youngestchild

    %%%%VARIABLE GROUP 1: 1 NBHD-Inc, 2 NBHD UninsMinors
    grp1E  = [1; 1; zeros(16,1); zeros(31,1)] ;
    grp1L  = [zeros(18,1); 1; 1; zeros(29,1)] ;
    grp1EL = [1; 1; zeros(16,1); 1; 1; zeros(29,1)] ;
    %%%%VARIABLE GROUP 2E: 3 HELPER_ADULT, 4 HELPER_PEER 
    grp2E  = [zeros(2,1); 1; 1; zeros(14,1); zeros(31,1)] ;
    %%%%VARIABLE GROUP 2L: 6 HELPER_ADULT, 7 HELPER_PEER, 8 MathFav, 9 MathLeast, 14 EXTRINSIC, 15 INTRINSIC
    grp2L  = [zeros(18,1); zeros(5,1); 1; 1; 1; 1; zeros(4,1); 1; 1; zeros(16,1)] ; 
    %%%%VARIABLE GROUP 2EL: 
    grp2EL = [zeros(2,1); 1; 1; zeros(14,1); zeros(5,1); 1; 1; 1; 1; zeros(4,1); 1; 1; zeros(16,1)] ;
    %%%%VARIABLE GROUP 3E: 5 fem, 6 Black, 7 Hispanic, 10 Grade-5
    grp3E  = [zeros(4,1); 1; 1; 1; zeros(2,1); 1; zeros(8,1); zeros(31,1)] ;
    %%%%VARIABLE GROUP 3L: 16 fem, 17 Black, 18 Hispanic, 21 Grade-5
    grp3L  = [zeros(18,1); zeros(15,1); 1; 1; 1; zeros(2,1); 1; zeros(10,1)] ;
    %%%%VARIABLE GROUP 3EL:
    grp3EL = [zeros(4,1); 1; 1; 1; zeros(2,1); 1; zeros(8,1); zeros(15,1); 1; 1; 1; zeros(2,1); 1; zeros(10,1)] ;
    %%%%VARIABLE GROUP 4E: 8 Dist2, 9 Dist3
    grp4E  = [zeros(7,1); 1; 1; zeros(9,1); zeros(31,1)] ;
    %%%%VARIABLE GROUP 4L: 19 Dist2, 20 Dist3
    grp4L  = [zeros(18,1); zeros(18,1); 1; 1; zeros(11,1)] ;
    %%%%VARIABLE GROUP 4EL: 
    grp4EL = [zeros(7,1); 1; 1; zeros(9,1); zeros(18,1); 1; 1; zeros(11,1)] ;
    %%%%VARIABLE GROUP 5L: 3 #GamingSys, 4 GamingWkDay, 5 WkDayNet, 10 FracSocialSuperv, 11 Sports, 12 music, 13 OtherActiv
    grp5L  = [zeros(18,1); zeros(2,1); 1; 1; 1; zeros(4,1); 1; 1; 1; 1; zeros(18,1)] ;
    %%%%VARIABLE GROUP 6E: 12 NO_INTERNET, 13 MOBILEFRAC, 14 TABLETFRAC 
    grp6E  = [zeros(11,1); 1; 1; 1; zeros(4,1); zeros(31,1)] ;
    %%%%VARIABLE GROUP 6L: 23 TimeStudy, 24 TimeScreen, 25 NO_INTERNET, 26 MOBILEFRAC, 27 TABLETFRAC
    grp6L  = [zeros(18,1); zeros(22,1); 1; 1; 1; 1; 1; zeros(4,1)] ;
    %%%%VARIABLE GROUP 6EL:  
    grp6EL = [zeros(11,1); 1; 1; 1; zeros(4,1); zeros(22,1); 1; 1; 1; 1; 1; zeros(4,1)] ;
    %%%%VARIABLE GROUP 7E: 15 InvolvedParent, 16 BigFam, 17 middlechild, 18 youngestchild
    grp7E  = [zeros(14,1); 1; 1; 1; 1; zeros(31,1)] ;
    %%%%VARIABLE GROUP 7L: 28 InvolvedParent, 29 BigFam, 30 middlechild, 31 youngestchild
    grp7L  = [zeros(18,1); zeros(27,1); 1; 1; 1; 1] ;
    %%%%VARIABLE GROUP 7EL: 
    grp7EL = [zeros(14,1); 1; 1; 1; 1; zeros(27,1); 1; 1; 1; 1] ;

    VarGroups = [grp1E grp1L grp1EL grp2E grp2L grp2EL grp3E grp3L grp3EL grp4E grp4L grp4EL grp5L grp6E grp6L grp6EL grp7E grp7L grp7EL] ;
end



logLRestarts0  = [] ;
ReStartMatrix  = [] ;
RestartMethod  = [] ;

for testindx = 1:length(VarGroups(1,:))
    %%%%METHOD 1: RE-OPTIMIZE THE ML OBJECTIVE WHILE CONSTRAINING EACH SET OF VARGROUP COEFFICIENTS TO EQUAL ZERO; ADD EACH RESULTING PARAMETER VECTOR TO THE SET OF RE-START POINTS
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp(strcat('Now doing hold-out optimization for_',num2str(testindx),'_of_',num2str(length(VarGroups(1,:))),'_VarGroup vectors...'))
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    [betaregtest,MLEouttest] = ...
                TypeRegressionEstimatorSmoothed(Y_E(useindx),X_E(useindx,:),Y_L(useindx),X_L(useindx,:),...
                Q(useindx),con(useindx),fem(useindx),blk(useindx),hsp(useindx),...
                LPointEst.domE,LPointEst.threshold1,LPointEst.threshold2,LPointEst.threshold3,...
                betareg,wts(useindx),0.1,EqualVariance,EqualCorrelation,1,10^-6,VarGroups(:,testindx)) ;
            [MLEout.logLval MLEouttest.logLval (MLEout.logLval-MLEouttest.logLval)] %#ok
            [betaregtest,MLEouttest] = ...
                TypeRegressionEstimatorSmoothed(Y_E(useindx),X_E(useindx,:),Y_L(useindx),X_L(useindx,:),...
                Q(useindx),con(useindx),fem(useindx),blk(useindx),hsp(useindx),...
                LPointEst.domE,LPointEst.threshold1,LPointEst.threshold2,LPointEst.threshold3,...
                betaregtest,wts(useindx),0.2,EqualVariance,EqualCorrelation,1,10^-6,VarGroups(:,testindx)) ;
            [MLEout.logLval MLEouttest.logLval (MLEout.logLval-MLEouttest.logLval)] %#ok

    ReStartMatrix = [ReStartMatrix betaregtest] ; %#ok
    logLRestarts0  = [logLRestarts0 MLEouttest.logLval] ; %#ok
    RestartMethod = [RestartMethod 1] ; %#ok
end

%%%%METHOD2: FOR EACH VARGROUP VECTOR, SCALE CORRESPONDING PARAMETERS UP/DOWN BY A FACTOR OF c\in[2,4,16], AND ADD RESULT TO THE SET OF RE-START POINTS
    disp('')
    disp('')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('')
    disp('')
for testindx = 1:length(VarGroups(1,:))
    temp = betareg ;
    temp(VarGroups(:,testindx)==1) = temp(VarGroups(:,testindx)==1)*2 ;
    ReStartMatrix = [ReStartMatrix temp] ; %#ok
    logLRestarts0  = [logLRestarts0 nan] ; %#ok
    RestartMethod = [RestartMethod 2] ; %#ok
    temp = betareg ;
    temp(VarGroups(:,testindx)==1) = temp(VarGroups(:,testindx)==1)*(1/2) ;
    ReStartMatrix = [ReStartMatrix temp] ; %#ok
    logLRestarts0  = [logLRestarts0 nan] ; %#ok
    RestartMethod = [RestartMethod 2] ; %#ok
    temp = betareg ;
    temp(VarGroups(:,testindx)==1) = temp(VarGroups(:,testindx)==1)*4 ;
    ReStartMatrix = [ReStartMatrix temp] ; %#ok
    logLRestarts0  = [logLRestarts0 nan] ; %#ok
    RestartMethod = [RestartMethod 2] ; %#ok
    temp = betareg ;
    temp(VarGroups(:,testindx)==1) = temp(VarGroups(:,testindx)==1)*(1/4) ;
    ReStartMatrix = [ReStartMatrix temp] ; %#ok
    logLRestarts0  = [logLRestarts0 nan] ; %#ok
    RestartMethod = [RestartMethod 2] ; %#ok
    temp = betareg ;
    temp(VarGroups(:,testindx)==1) = temp(VarGroups(:,testindx)==1)*16 ;
    ReStartMatrix = [ReStartMatrix temp] ; %#ok
    logLRestarts0  = [logLRestarts0 nan] ; %#ok
    RestartMethod = [RestartMethod 2] ; %#ok
    temp = betareg ;
    temp(VarGroups(:,testindx)==1) = temp(VarGroups(:,testindx)==1)*(1/16) ;
    ReStartMatrix = [ReStartMatrix temp] ; %#ok
    logLRestarts0  = [logLRestarts0 nan] ; %#ok
    RestartMethod = [RestartMethod 2] ; %#ok
end



%%
format shortg
ResultMatrix = nan(size(ReStartMatrix)) ;
logLRestarts = nan(size(logLRestarts0)) ;
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
for testindx = 7:length(ReStartMatrix)
    disp('')
    disp('%%%%-------------------------------------------------------------------------------------------')
    disp('')
    disp(strcat('Now running optimization for_',num2str(testindx),'_of_',num2str(length(ReStartMatrix)),'_Re-Start vectors (this one generated by METHOD_',num2str(RestartMethod(1,testindx)),')...'))
    disp('Quasi-Newton, Interior-Point Algorithm:')
    [betaregtest,MLEouttest] = ...
        TypeRegressionEstimatorSmoothed(Y_E(useindx),X_E(useindx,:),Y_L(useindx),X_L(useindx,:),...
        Q(useindx),con(useindx),fem(useindx),blk(useindx),hsp(useindx),...
        LPointEst.domE,LPointEst.threshold1,LPointEst.threshold2,LPointEst.threshold3,...
        ReStartMatrix(:,testindx),wts(useindx),0.1,EqualVariance,EqualCorrelation,0,10^-5) ;
    [MLEout.logLval MLEouttest.logLval (MLEout.logLval-MLEouttest.logLval)] %#ok
    disp('Quasi-Newton, SQP Algorithm:')
    [betaregtest,MLEouttest] = ...
        TypeRegressionEstimatorSmoothed(Y_E(useindx),X_E(useindx,:),Y_L(useindx),X_L(useindx,:),...
        Q(useindx),con(useindx),fem(useindx),blk(useindx),hsp(useindx),...
        LPointEst.domE,LPointEst.threshold1,LPointEst.threshold2,LPointEst.threshold3,...
        ReStartMatrix(:,testindx),wts(useindx),0.3,EqualVariance,EqualCorrelation,0,10^-5) ;
    [MLEout.logLval MLEouttest.logLval (MLEout.logLval-MLEouttest.logLval)] %#ok
    disp('PatternSearch, NUPS-MADS Algorithm:')
    [betaregtest,MLEouttest] = ...
        TypeRegressionEstimatorSmoothed(Y_E(useindx),X_E(useindx,:),Y_L(useindx),X_L(useindx,:),...
        Q(useindx),con(useindx),fem(useindx),blk(useindx),hsp(useindx),...
        LPointEst.domE,LPointEst.threshold1,LPointEst.threshold2,LPointEst.threshold3,...
        betaregtest,wts(useindx),4,EqualVariance,EqualCorrelation,0,10^-5) ;
    [MLEout.logLval MLEouttest.logLval (MLEout.logLval-MLEouttest.logLval)] %#ok
    disp('PatternSearch, CLASSIC Algorithm:')
    [betaregtest,MLEouttest] = ...
        TypeRegressionEstimatorSmoothed(Y_E(useindx),X_E(useindx,:),Y_L(useindx),X_L(useindx,:),...
        Q(useindx),con(useindx),fem(useindx),blk(useindx),hsp(useindx),...
        LPointEst.domE,LPointEst.threshold1,LPointEst.threshold2,LPointEst.threshold3,...
        betaregtest,wts(useindx),1,EqualVariance,EqualCorrelation,0,10^-5) ;
    [MLEout.logLval MLEouttest.logLval (MLEout.logLval-MLEouttest.logLval)] %#ok

    ResultMatrix(:,testindx) = betaregtest ;
    logLRestarts(1,testindx) = MLEouttest.logLval ;
end

diary off






